/*
 *  \file Settings.h
 *  GRE
 *
 *  Created by Kutlak Roman on 07/09/2011.
 *  Copyright 2011 University of Aberdeen. All rights reserved.
 *
 */

#ifndef Settings_h 
#define Settings_h

#include <string>
#include <map>
#include <mutex>

namespace kutlak {
namespace roman {
namespace gre {
    
    /*!
     * \brief A class that reads settings from user space.
     *  The class uses a singleton pattern. On creation,
     *  it looks into ~/.gre and looks for the gre.settings file.
     *
     *  Settings is a optional singleton class.
     */
    class Settings { 
    public: 
        typedef std::map<std::string, std::string> SettingsContainer_t;
        
#pragma mark -
#pragma mark lifecycle

    public:
        Settings(const std::string& path);
        
        Settings(const Settings& from) = delete;
        
        Settings& operator=(const Settings& from) = delete;
        
        ~Settings(void);
        
        static Settings& Instance();
        
    private:
        void Init(const std::string& path);
        
#pragma mark -
#pragma mark operations
    public:
        
        std::string GetSetting(const std::string& key);
        
        static std::string GetEnvironmentVar(const std::string& key);

    private:
        SettingsContainer_t mSpecSettings;
        
        static std::once_flag sFlag; // flag for initialization
        
    };
}
}
}
#endif // Settings_h
